﻿using System;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.DirectShow.Filters;
using System.Threading;
using System.Windows.Media.DirectShow.Vorbis;

namespace System.Windows.Media.DirectShow.Ogg
{
    internal class OggVorbisOutputPin : BaseOutputPin
    {


        private OggVorbisDecoder filter;
        private AMMediaType[] _mediaTypes;
        private WaveFormatExtensible format;

        public OggVorbisOutputPin(OggVorbisDecoder filter, AMMediaType mt)
            : base(filter)
        {
            this.filter = filter;
            this._mediaTypes = new AMMediaType[] { mt };
            this.format = (WaveFormatExtensible)mt.Format;
        }

        public override System.Collections.Generic.IEnumerable<AMMediaType> MediaTypes
        {
            get { return _mediaTypes; }
        }

        public override string Name
        {
            get { return "Wave out"; }
        }

        protected internal override void DeliverAsync(IMediaSample sample)
        {
            TimeSpan start = TimeSpan.FromSeconds(sample.StartMediaTime / (double)format.AverageBytesPerSecond);
            TimeSpan end = TimeSpan.FromSeconds(sample.EndMediaTime / (double)format.AverageBytesPerSecond);

            // Set sample parameters
            sample.StartMediaTime = sample.StartMediaTime;
            sample.EndMediaTime = sample.EndMediaTime;
            sample.StartTime = start;
            sample.EndTime = end;
            sample.MediaType = this._mediaTypes[0];

            base.DeliverAsync(sample);
        }


    }
}
